<template>
  <div class="home">
    <div class="platformleft">
      <div style="padding: 30px 20px">
        <div class="logobox" @click="goindex">
          <img
            style="width: 60px; height: 60px; margin-right: 5px"
            src="~@/assets/icon/gslogo.png"
          />
          <span>中字软科技</span>
        </div>
        <div>
          <el-button
            style="width: 100%; margin-bottom: 10px"
            type="primary"
            icon="el-icon-plus"
            @click="added()"
            >{{$t('message.menu.newchat')}}</el-button
          >
          <span style="color: #9e9e9e">{{$t('message.menu.show')}}</span>
        </div>
      </div>
      <!-- 可调节显示条数 -->
      <div class="lefttitle" style="height: 400px; overflow: hidden">
        <div v-for="(item, index) in sessiondata" :key="index">
          <el-button plain @click="chatben(item)">
            <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
              {{ item.chatSummary }}
            </div>
          </el-button>
        </div>
      </div>
    </div>
    <div class="chatright">
      <div class="headright">
        <el-dropdown style="margin-right: 30px;" @command="setLanguage">
            <div class="el-dropdown-link">
              <img style="width: 25px;" src="@/assets/img/icon_yy.svg" class="m_icon" alt="">
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="zh">{{$t('message.menu.langsZh')}}</el-dropdown-item>
              <el-dropdown-item command="en">{{$t('message.menu.langsEn')}}</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown @command="loginout">
          <div style="text-align: right; padding-right: 15px">
            <img style="cursor: pointer" src="~@/assets/icon/icon_txbig.png" alt="" />
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="exit">{{$t('message.menu.logOut')}}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <div style="padding: 0 60px">
        <div
          style="
            margin-bottom: 90px;
            display: flex;
            justify-content: center;
            align-items: center;
          "
        >
          <img
            style="width: 90px; height: 90px; margin-right: 10px"
            src="~@/assets/icon/gslogo.png"
          />
          <span style="font-size: 26px; font-weight: 600">中字软科技</span>
        </div>
        <div class="questioninput">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 4 }"
            :placeholder="$t('message.menu.question')"
            v-model="question"
            @keyup.enter.native="gochat()"
          ></el-input>
          <div style="text-align: right">
            <el-button
              style="margin: 10px"
              type="primary"
              size="small"
              @click.native.prevent="gochat()"
              >{{$t('message.menu.pass')}}</el-button
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      total: 3, //默认数据总数
      value: false,
      pageConfig: {
        page: 1,
        pageSize: 10,
      },
      question: "",
      sessiondata: [],
    };
  },
  computed: {
    lang(){
          return this.$i18n.locale
    },
  },

  mounted() {},
  created() {
    let that = this;
    that.getsession();
  },
  methods: {
    getswitch() {
      let that = this;
      that.switchview = true;
    },
    closeswitch() {
      let that = this;
      that.switchview = false;
    },
    chatben(item) {
      this.$router.push({ name: "newchat", query: { id: item.interactionId } });
    },
    setLanguage(command){
      if(this.$i18n.locale!==command){
        this.$i18n.locale = command;
        localStorage.setItem('langs',command);
        location.reload()
      }
    },
    keydown(e) {
      console.log(e);
      if (!e.shiftKey && e.keyCode == 13) {
        e.cancelBubble = true; //ie阻止冒泡行为
        e.stopPropagation(); //Firefox阻止冒泡行为
        e.preventDefault(); //取消事件的默认动作*换行
        //以下处理发送消息代码
        if (e.keyCode == 13) {
        }
      }
    },

    loginout(command) {
      let that = this;
      if ((command = "exit")) {
        that.$api.post("/auth/logout", {}).then((res) => {
          that.$store.commit("login", "");
          that.$router.push({ name: "login" });
        });
      }
    },
    handleCurrentChange(val) {
      this.pageConfig.page = val;
      this.getsession();
      // this.loading = true
    },
    // 新建聊天
    added() {
      this.$router.push({ name: "added" });
    },
    goindex() {
      this.$router.push({ name: "index" });
    },
    // 首次聊天
    gochat(e) {
      if (this.question != "" && this.question != null) {
        this.$router.push({ name: "Chat", query: { question: this.question } });
      } else {
        this.$message.error("问题不能为空");
      }
    },
    // 获取会话记录
    getsession() {
      let that = this;
      that.$api.post("/chat/history/list", {}).then((res) => {
        let list = [];
        res.records.map((item, index) => {
          list.push({
            interactionId: item.interactionId,
            chatSummary: item.chatSummary,
            clicktype: true,
          });
        });
        that.sessiondata = list;
      });
    },
  },
};
</script>
<style lang="stylus" scoped>
.home
  display flex
  min-height calc(100vh - 0px)

.platformleft{
  width:20%;
  background:#fff;
  // padding:30px;
}
.chatright{
  width:80%;
  padding: 30px 50px;
  position: relative;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-image: url('~@/assets/icon/bg_index.png');
}
.logobox{
  cursor: pointer;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  span{
    width: 70%;
    font-size:18px;
    font-weight:600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
>>>.el-textarea__inner{
  border: none;
}
.title{
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    height: 40px;
    line-height: 40px;
    padding: 0 30px;
    cursor:pointer;
}
.lefttitle{
  >>>.el-button{
    border: 4px solid transparent;
    width: 100%;
    height:40px;
    border-radius: 0px;
  }
  >>>.el-button:hover{
    background:#F1F1F1;
    color:#606266;
  }
  >>>.el-button:focus{
    background:#F1F1F1;
    color:#606266;
    border-right:4px solid #0091FF
  }
}
.pagination{
  text-align: center;
  margin: 15px 0;
}
.questioninput{
  background: #fff;
  margin-bottom: 80px;
  border-radius: 10px;
  box-shadow: 0px 0px 17px 2px rgba(0, 0, 0, 0.08);
}
.headright{
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
>>>.el-switch{
  padding-right: 30px;
}
</style>
